/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
/*
 * catchit
 * Copyright (C) 2013 Ryan Grinkewitz <graphite@Toto>
 * 
 */

#include "level-generator.h"
#include <iostream>



LevelGenerator::LevelGenerator(){

	srand (time(NULL));
}

LevelGenerator::~LevelGenerator(){

}

Level* LevelGenerator::generateLevel(int difficulty,int level_size, Level* previousLevel){

	Level* newLevel = new Level(level_size);


	if(previousLevel == NULL)
	{
		//generate a fresh level
		for(int i = 0; i < level_size; i++){

				newLevel->insertPlatform (new Platform(i), i);
		}
	}else{
		//generate a level based on previous level
		for(int i = 0; i < level_size; i++){
			int addPlatform = rand()%(6 - difficulty);
			if(addPlatform){
				newLevel->insertPlatform (new Platform(i), i);
			}
		}		
	}

//	std::cout << "New level: " << std::endl;
	//for(int i = 0; i < level_size; i++){
	//	std::cout << "  Platform " << i << " is ";
		//if(newLevel->getPlatform (i) == NULL){
		//	std::cout << "NULL" << std::endl;
	//	}else{
	//		std::cout << "not NULL" << std::endl;
		//}
//	}
	return newLevel;
}